import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { UserService } from '../users/user.service';

@Injectable()
export class AuthService {
  constructor(
    private usersService: UserService,
    private jwtService: JwtService,
  ) {}
  async signIn(phone: string, code: string) {
    const user = await this.usersService.queryUser(phone);
    if (user) {
      const payload = { sub: user.id, phone: user.phone };
      console.log(await this.jwtService.signAsync(payload));
      return {
        access_token: await this.jwtService.signAsync(payload),
      };
    }
  }
}
